package mlz.d_interface.demo02;

import java.util.ArrayList;

/*
第2套方案:能打印出班级全部学生的信息(包含男女人数);能打印班级全部学生的平均分(要求是去掉最高分、最低分)
 */
public class StudentOperatorImpl2 implements StudentOperator{
    @Override
    public void printAllInfo(ArrayList<Student> students) {
        System.out.println("--打印全部学生的信息:--");

        //记录男的总数
        int count1 = 0;
        //记录女的总数
        int count2 = 0;

        for (int i = 0; i < students.size(); i++) {
            //每个学生
            Student s = students.get(i);
            System.out.println("姓名:" + s.getName() + ",性别" + s.getSex() + ",分数:" + s.getScore());
            if (s.getSex() == '男'){
                count1++;
            }else {
                count2++;
            }
        }
        System.out.println("男生人数是:" + count1 + ",女生人数是:" + count2);
    }

    @Override
    public void printAvgScore(ArrayList<Student> students) {
        //定义总分
        double all = 0.0;
        //记录最高分
        double max = students.get(0).getScore();
        //double max = -1;
        //记住最低分
        double min = students.get(0).getScore();

        for (int i = 0; i < students.size(); i++) {
            //下标:0
            Student s = students.get(i);
            //求最高分
            if (s.getScore() > max) {
                max = s.getScore();
            }
            if (s.getScore() < min) {
                min = s.getScore();
            }
            all += s.getScore();
        }
        System.out.println("学生的最高分:" + max);
        System.out.println("学生最低分:" + min);

        System.out.println("平均分:" + (all - max - min) / students.size());
    }
}






















